﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreSample.Services;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace NetCoreSample.Controllers
{
    [Route("api/demo")]
    public class DemoController : Controller
    {
        private IDemoUserService _userService;
        public DemoController(IDemoUserService userService)
        {
            _userService = userService;
        }


        [HttpGet("life-time")]
        public string DemoLiftTime(
            [FromServices] IDemoSingletonService singletonA,
            [FromServices] IDemoSingletonService singletonB,
            [FromServices] IDemoScopedService scopedA,
            [FromServices] IDemoScopedService scopedB,
            [FromServices] IDemoTransientService transientA,
            [FromServices] IDemoTransientService transientB
        )
        {
            Console.WriteLine($"singletonA:{singletonA.GetHashCode()}");
            Console.WriteLine($"singletonB:{singletonB.GetHashCode()}");
            Console.WriteLine($"scopedA:{scopedA.GetHashCode()}");
            Console.WriteLine($"scopedB:{scopedB.GetHashCode()}");
            Console.WriteLine($"transientA:{transientA.GetHashCode()}");
            Console.WriteLine($"transientB:{transientB.GetHashCode()}");
            Console.WriteLine("---------------------------------------");
            return "value";
        }


        [HttpGet("multi-register")]
        public void MultiRegister(
            [FromServices]IEnumerable<IDemoUserService> userServices
        )
        {
            foreach (var service in userServices)
            {
                Console.WriteLine($"multi-register:{service.GetHashCode()}");
            }
        }
        
        [HttpGet("generic")]
        public void GenericService(
            [FromServices]IDemoGenericService<int> genericServices
        )
        {
            Console.WriteLine($"genericServices:{genericServices.GetHashCode()}");
        }
    }
}
